package com.drug.web.controller.system;

import com.alibaba.fastjson.JSONObject;
import com.drug.common.constant.Constants;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.domain.model.LoginBody;
import com.drug.framework.web.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController()
@RequestMapping("wx")
public class WxLoginController {
    @Autowired
    private SysLoginService loginService;
    @Value("rsa")
    private String privateKey;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody) throws Exception {
        AjaxResult ajax = AjaxResult.success();
        //解密
       /* byte[] decodedData = RSAUtil.decryptByPrivateKey(loginBody.getPassword(), privateKey);
        String outputStr = new String(decodedData);
        loginBody.setUsername(outputStr);*/
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(Constants.TOKEN, token);
        ajax.put(Constants.DATA, jsonObject);
        return ajax;
    }

}
